for (Object object : list) [java] construction

Posted by EugeneP on Stack Overflow See other posts from Stack Overflow or by EugeneP
Published on 2010-05-18T14:10:21Z Indexed on 2010/05/18 14:20 UTC
Read the original article Hit count: 122

Filed under:
|
|

My question, is, whether the sequence of elements picked from a list will always be the same,

is this construction behaviour is deterministic for

           java "List"s - descendants of java.util.List

2) question, if I use

for(Object o: list)
construction and inside the loop's body increment a variable, will it be the index of list's elements? So, how it goes through list's elements, from 0 to size()-1 or chaotically?

                   List.get(i) 

will always return this element?

3) question ( I suppose for the 2-nd question the answer will be negative, so:)

         for (int i=0; i < list.size(); i++) {
         }

is the best way if I need to save the index of an element and later get it back from a list by its id?

© Stack Overflow or respective owner

Related posts about java

Related posts about collections